class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            cate: [],
            screenshotarr: '',
            qrcode: '',
            id: 0,
            enlargeimg: "",
            modisshow: !1,
            data: {},
            reason: '',
            filesrchtml: [], filesrcarr: [],
        };
    }

    componentDidMount() {
        this.setState({ showloading: 'ON' })
        let that = this;
        let id = GetQueryString('id')

        if (id != 'null' && id) {
            that.setState({ id }, () => {
                that.freshlist()
            })
        } else {
            window.location.href = "./recruit.html";
            that.setState({ showloading: '' })
        }


    }

    freshlist() {
        let { id } = this.state, that = this, filesrchtml = [], filesrcarr = [];
        Recruitgetdetail(id, res => {
            this.setState({ showloading: '' })
            if (res.issuccess == 1) {
                let data = res.data
                this.setState({ data, })
            }
        })

    }

    confirm(e) {
        this.setState({ confirmid: e, contents: '确定要通过审核吗？', setjk: 'confirm', }, () => {
            $('#myModal').modal('toggle');
        })

    }
    //急聘
    urgent(e) {
        this.setState({ urgentid: e, contents: '确定要修改成急聘吗？', setjk: 'edit', }, () => {
            $('#myModal').modal('toggle');
        })
    }
    confirmdel() {
        this.setState({ showloading: 'ON' })
        let { setjk } = this.state, that = this
        if (setjk == 'confirm') {
            let { confirmid, } = that.state

            Recruitcheck({ id: confirmid, }, res => {
                if (res.issuccess == 1) {
                    alert('操作成功')
                    $('#myModal').modal('toggle');
                    window.location.href = "./recruit.html";

                } else {
                    that.setState({ showloading: '', })
                    $('#myModal').modal('toggle');
                    alert(res.msg)
                }
            })

        } else if (setjk == 'edit') {
            let { urgentid, } = that.state
            Recruitseturgent(urgentid, res => {
                if (res.issuccess == 1) {
                    alert('设置成功')
                    $('#myModal').modal('toggle');
                    window.location.href = "./recruit.html";

                } else {
                    that.setState({ showloading: '', })
                    $('#myModal').modal('toggle');
                    alert(res.msg)
                }
            })

        }
    }

    cancal(e) {
        console.log(e, 'cancel')
        this.setState({ refuseid: e })
    }
    reasonsubmit() {
        let { refuseid, reason, userid } = this.state, that = this;
        if (reason == '') {
            alert('请输入原因')
            return;
        }
        this.setState({ showloading: 'ON' })
        let data = { id: refuseid, reason }
        Recruitcheck(data, res => {
            this.setState({ showloading: '' })
            if (res.issuccess == 1) {
                alert('操作成功')
                window.location.href = "./recruit.html";
            } else {
                alert(res.msg)
            }
        })
        console.log(data, 'reasonsubmit');

    }
    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }

    toback() {
        window.location.href = "./recruit.html";
    }

    render() {
        let { filesrchtml, data, modisshow, enlargeimg, reason, contents } = this.state;
        return (
            <div className="breadLinebox">
                <Loading hidden={this.state.showloading != 'ON'} />
                <Modal content={contents} click={this.confirmdel.bind(this)} />
                {/* <div className="enlargeimgmod" style={{ display: modisshow ? "" : "none" }}  >
                    <div className="enlargeimg" >
                        <img src="./src/toleft.png" className="toimg toleft" onClick={this.setenlargeimg.bind(this, 0)} />
                        <img src={enlargeimg} onClick={this.hide123.bind(this)} />
                        <img src="./src/toright.png" className="toimg toright" onClick={this.setenlargeimg.bind(this, 1)} />
                    </div>
                </div> */}
                <div className="modal fade" id="modalOne" >
                    <div className="modal-dialog">
                        <div className="modal-content">

                            <div className="modal-body">
                                <div className="input-group">
                                    <span className="input-group-addon">拒绝理由</span>
                                    <input id='name' onChange={this.inputchange.bind(this, 'reason')} value={reason} type="text" placeholder='请输入拒绝理由' className="input" />
                                </div>

                            </div>
                            <div className="modal-footer border">
                                <button type="button" className="closemod" data-dismiss="modal">关闭</button>
                                <button type="button" onClick={this.reasonsubmit.bind(this)} data-dismiss="modal" className="submitmod">提交</button>
                            </div>

                        </div>
                    </div>
                </div>
                <div className='content_wrap panel-default content_wrap'>
                    <div className="breadLine">
                        <div className="img">
                            <img src='./src/lm_order1.png' />
                            <span onClick={this.toback.bind(this)} style={{ cursor: 'pointer' }}>招工管理</span> {">"} 招工详情
                        </div>
                    </div>
                    <div className="content form">
                        <div className="formtitle">
                        </div>
                        <div className="formbox">
                            <div className="statebox">
                                <div>{data.state == 'APPLYING' ? '审核中' : data.state == 'FAIL' ? '申请失败' : '申请成功'}</div>
                                <p style={{ display: data.state == "FAIL" ? '' : 'none' }} className="failreason">失败原因：{data.reason}</p>
                            </div>
                            <div className="formcontent">

                                {/* 项目信息 */}
                                <div>
                                    <div className="ordertitle">
                                        项目信息
                                    </div>
                                    <div className="ordercont">
                                        <div className="input-group flex">
                                            <span className="input-group-addon">标题：</span>
                                            <span className="inputcontent">{data.title}</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">招聘状态：</span>
                                            <span className="inputcontent">{data.recruitstate == "RECRUITING" ? "招聘中" : data.recruitstate == "RECRUITFULL" ? "已招满" : "未知"}</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">工种：</span>
                                            <span className="inputcontent">{data.worktypename}-{data.worksubtypename}</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">人数：</span>
                                            <span className="inputcontent">{data.recruitsnum}人</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">联系人：</span>
                                            <span className="inputcontent">{data.contacts}</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">联系电话：</span>
                                            <span className="inputcontent">{data.phone}</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">薪资：</span>
                                            <span className="inputcontent">{data.salary}</span>
                                        </div>
                                        <div className="input-group flex cflex">
                                            <span className="input-group-addon">项目地址：</span>
                                            <span className="inputcontent">{data.province + data.city + data.district}</span>
                                        </div>
                                        <div className="input-group flex">
                                            <span className="input-group-addon">是否急聘：</span>
                                            <span className="inputcontent">{data.isurgent == '1' ? '是' : '否'}</span>
                                        </div>

                                        <div className="input-group flex">
                                            <span className="input-group-addon">发布日期：</span>
                                            <span className="inputcontent">{getLocalTime1(data.updateDate * 1000)}</span>
                                        </div>

                                        <div className="input-group flex cflex">
                                            <span className="input-group-addon">备注：</span>
                                            <span className="inputcontent description">{data.detail || '无'}</span>
                                        </div>

                                    </div>
                                </div>
                                {/* end 项目信息 */}



                            </div>
                            <div className="submitbox">
                                <button type="button" onClick={this.confirm.bind(this, data.id)} className="submitbutton" style={{ marginRight: "20px", display: data.state == "APPLYING" ? "" : "none" }}>通过</button>
                                <button type="button" onClick={this.cancal.bind(this, data.id)} data-toggle="modal" style={{ marginRight: "20px", display: data.state == "APPLYING" ? "" : "none" }} data-target="#modalOne" className="submitbutton">拒绝</button>
                                <button type="button" onClick={this.urgent.bind(this, data.id)} data-toggle="modal" style={{ marginRight: "20px", display: data.state == "SUCCESS" && data.isurgent != '1' ? "" : "none" }} >修改成急聘</button>
                                <button type="button" onClick={this.toback.bind(this)} className="submitbutton">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        )

    }
}





ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='recruit' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)